package com.example.springdemo;

import com.example.springdemo.Utils.LogFileName;
import com.example.springdemo.Utils.LoggerUtils;
import com.example.springdemo.entity.User;
import com.example.springdemo.service.UserService;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.util.Assert;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.Random;

@SpringBootTest
class SpringDemoApplicationTests {
    Logger USER = LoggerUtils.logger(LogFileName.USER);
    @Resource
    UserService userService;

    @Test
    void contextLoads() {
    }

    @Test
    public void testLog() {
        USER.warn(LogFileName.USER.toString());
        USER.info(" 用户信息");
    }
    //java 8 新特性测试 Stream
    //filter 方法用于通过设置的条件过滤出元素。以下代码片段使用 filter 方法过滤出空字符串：

    @Test
    public void testFilter() {
        int[] test = {1, 2, 3, 4, 5};
        long num = Arrays.stream(test).filter(v -> v > 0).count();
        USER.info("结果为==》{}", num);
    }

    //Stream 提供了新的方法 limit 方法用于获取指定数量的流。 以下代码片段使用 limit 方法打印出 10 条数据：
    @Test
    public void testLimit() {
        Random random = new Random();
        long count = random.ints().peek(v -> USER.info(String.valueOf(v))).limit(10).count();
        //断言
        Assert.isTrue((count == 10), "返回正确");
    }

    @Test
    public void testlistOf(){
//        int[] size= new  myList{2,3,4,5,6,1}.size();
        int size= List.of(1,2,7,3,4,6,7,34,22).size();
        USER.info(String.valueOf(size));
        System.out.println(size);
        Assert.isTrue((size==15),"大量初始化成功");
    }
    @Test
    public void testStream() {
        Random random = new Random();
        long count = random.ints().peek(v -> USER.info(String.valueOf(v))).limit(10).count();
        Assert.isTrue((count == 10), "返回正确");
    }
    @Test
    public void testCrud(){
        User user=new User("张思",18);
        userService.save(user);
        System.out.println(userService.findAll());
    }
}
